//
//  TB1TableViewCell.m
//  CollTest
//
//  Created by codew on 9/13/21.
//

#import "TB1TableViewCell.h"

@interface TB1TableViewCell ()

@property (nonatomic, strong) UIImageView * imageViewIcon;
@property (nonatomic, strong) UILabel * lblName;
@property (nonatomic, strong) UILabel * lblSummary;
@property (nonatomic, strong) UILabel * lblContent;

@end

@implementation TB1TableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubviews];
        [self makeContraints];
    }
    return self;
}



#pragma mark - private initUI
//MARK:初始化
- (void)initSubviews {
//    self.contentView.backgroundColor = [CPSCustomerTheme colorFFFFFF];
    
    
    [self.contentView addSubview:self.imageViewIcon];
    [self.contentView addSubview:self.lblName];
    [self.contentView addSubview:self.lblSummary];
    [self.contentView addSubview:self.lblContent];
    
    [self deBugUI];
    
}

- (void)updateCellWithItem:(NSString *)text
{
    self.lblContent.text = text;
}

- (void)deBugUI
{
    self.lblName.text = @"有限公司注册有限公司注册有限公司注册有限公司注册";
    self.lblSummary.text = @"这个值不必特别精准，只要和cell的可能高度相差不是很大就可以了";
    self.lblContent.text = @"项目中遇到一个坑，项目中某个界面tableview的cell使用了动态变高，cell的高度设置为UITableViewAutomaticDimension，手头的iOS11、iOS12都可以正常显示，没有问题。后来陆续有客户反馈该界面显示异常，调查后发现用户都是iOS10、iOS9的系统，检查代码，确认cell的内部约束正常，谷歌一顿搜索也没有找到原因.";
    
    NSShadow *shadow = [[NSShadow alloc]init];
    shadow.shadowBlurRadius = 4.0;
    shadow.shadowOffset = CGSizeMake(2.0f, 2.0f);
    shadow.shadowColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.08];
    NSAttributedString *attString=[[NSAttributedString alloc]initWithString:@"" attributes:@{NSShadowAttributeName:shadow}];
    self.lblSummary.attributedText=attString;
    
    
//    NSString * stringContent = [NSString stringWithFormat:@"%@次观看",numberStr];
//    NSShadow *shadow = [[NSShadow alloc]init];
//    shadow.shadowBlurRadius = 4.0;
//    shadow.shadowOffset = CGSizeMake(2.0f, 2.0f);
//    shadow.shadowColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.08];
//    NSAttributedString *attString = [[NSAttributedString alloc]initWithString:stringContent attributes:@{NSShadowAttributeName:shadow}];
//    self.lblViewsNumber.attributedText = attString;
//    

    
//    self.lblSummary.shadowColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
//    self.lblSummary.shadowOffset = CGSizeMake(2.0f, 2.0f);
//    self.lblSummary. BlurRadius= 6.0;
    
//    self.imageViewIcon.backgroundColor = kCPSCRandomColor;
//    self.lblName.backgroundColor = kCPSCRandomColor;
//    self.lblSummary.backgroundColor = kCPSCRandomColor;
//    self.lblContent.backgroundColor = kCPSCRandomColor;
//    self.lblContent.numberOfLines = 0;
}

- (void)makeContraints
{
    [self.imageViewIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.mas_equalTo(10);
        make.height.width.mas_equalTo(50);
    }];

    [self.lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageViewIcon.mas_top);
        make.left.equalTo(self.imageViewIcon.mas_right).offset(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(50);
    }];
    
    [self.lblSummary mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.lblName.mas_bottom).offset(10);
        make.left.equalTo(self.imageViewIcon.mas_right).offset(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(50);
    }];
    
    [self.lblContent mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.lblSummary.mas_bottom).offset(10);
        make.left.equalTo(self.imageViewIcon.mas_right).offset(10);
        make.right.bottom.mas_equalTo(-10);
    }];
}


#pragma mark - Getter Setter

- (UILabel *)lblName
{
    if (!_lblName) {
        
        UILabel * lblZy = [[UILabel alloc] init];
        lblZy.textColor = [UIColor colorWithHexString:@"#EC5330"];
        lblZy.font = [UIFont systemFontOfSize:22];
        lblZy.textAlignment = NSTextAlignmentLeft;
        
        _lblName = lblZy;
    }
    
    return _lblName;
}


- (UILabel *)lblSummary
{
    if (!_lblSummary) {
        
        UILabel * lblZy = [[UILabel alloc] init];
        lblZy.textColor = [UIColor colorWithHexString:@"#EC5330"];
        lblZy.font = [UIFont systemFontOfSize:22];
        lblZy.textAlignment = NSTextAlignmentLeft;
        lblZy.numberOfLines = 2;
        _lblSummary = lblZy;
    }
    
    return _lblSummary;
}


- (UILabel *)lblContent
{
    if (!_lblContent) {
        
        UILabel * lblZy = [[UILabel alloc] init];
        lblZy.textColor = [UIColor colorWithHexString:@"#EC5330"];
        lblZy.font = [UIFont systemFontOfSize:22];
        lblZy.textAlignment = NSTextAlignmentLeft;
        
        _lblContent = lblZy;
    }
    
    return _lblContent;
}

- (UIImageView *)imageViewIcon
{
    if (!_imageViewIcon) {
        
        UIImageView * imageViewIcon = [[UIImageView alloc] init];
        imageViewIcon.contentMode = UIViewContentModeScaleAspectFill;
        imageViewIcon.layer.cornerRadius = 20;
        imageViewIcon.layer.masksToBounds = YES;
        
        imageViewIcon.image = [UIImage imageNamed:@"c"];
        _imageViewIcon = imageViewIcon;
    }
    return _imageViewIcon;
}
@end
